<?php
	
	include_once("Database.class.php");
	class Users
	{
		function __construct($dbh = false, $rpc = false){
			$this->{'dbh'} = $dbh;
			$this->{'rpc'} = $rpc;
			#$dbh = false;
			if($dbh === false){
				$this->get_dbh();
			}
		}
		
		public function list_users(){
			$query = $dbh->query('select * from users');
			return $dbh->fetch_all($query);			
		}
		
		public function auth_user($username, $password){
			$query = $this->dbh->query("SELECT * FROM users WHERE username='%s' and password = PASSWORD('%s')", $username, $password);
			return $this->dbh->fetch_row($query);						
		}
		
		private function get_dbh(){
			global $cfg;
			
			$this->dbh = new Database(array(
				'server' => $cfg['database']['address'],
				'user'   => $cfg['database']['username'],
				'password' => $cfg['database']['password'],
				'database' => 'Simpleswitch'
			));			
		}
	}
?>
